package com.example.onlineeducation.adapter

import android.widget.ImageView
import com.example.onlineeducation.R
import com.example.onlineeducation.data.entity.BannerEntity
import com.example.onlineeducation.databinding.MainHomeImageFragmentBinding
import com.yc.jetpacklib.extension.ycIsNotEmpty
import com.yc.jetpacklib.extension.ycLoadImageNet
import com.yc.jetpacklib.extension.ycLoadImageRes
import com.yc.jetpacklib.recycleView.YcRecyclerViewAdapter


/**
 * Creator: sindi
 * Date: 2022/4/22 15:05
 * UseDes:
 */
class BannerAdapter : YcRecyclerViewAdapter<BannerEntity, MainHomeImageFragmentBinding>(MainHomeImageFragmentBinding::inflate) {
    override var mOnUpdate2: (MainHomeImageFragmentBinding.(position: Int, data: BannerEntity) -> Unit)? = { position: Int, data: BannerEntity ->
        iv.scaleType = ImageView.ScaleType.FIT_XY
        if (data.showDefault) {
            iv.ycLoadImageRes(R.drawable.ic_topic)
        } else {
            if (data.imgUrl.ycIsNotEmpty()) {
                iv.ycLoadImageNet(data.imgUrl, errorImg = R.drawable.ic_topic)
            } else {
                iv.ycLoadImageRes(R.drawable.ic_topic)
            }
        }
    }
}